home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / vesa18.zip / VESA_DOS.C < prev    next >
C/C++ Source or Header  |  1994-10-07  |  19KB  |  661 lines

  1. /* VESA package for emx/gcc --- Copyright (c) 1993 by Johannes Martin */
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <sys/hw.h>
  6. #include <conio.h>
  7.  
  8. #include "vesa.h"
  9. #include "vesa_dos.h"
  10. #include "vgaports.h"
  11.  
  12. #define STANDARD_MODES 3
  13. #define DEFAULT_MODES 23
  14.  
  15. static VESABOOL textmode = TRUE;
  16.  
  17. static VESAMODEINFO standard_infos[STANDARD_MODES]
  18.  = { { 0x1f, 0x7, 0x0, 64, 64, 0x0, 0x0, DosVesaSetWindow, DosVesaGetWindow,
  19.        80, 640,  480, 8, 16, 4,  4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  20.      { 0x1f, 0x7, 0x0, 64, 64, 0x0, 0x0, DosVesaSetWindow, DosVesaGetWindow,
  21.        320, 320,  200, 8,  8, 1,  8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  22.      { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0, DosVesaSetWindow, DosVesaGetWindow,
  23.        100, 800, 600, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } };
  24.  
  25. struct _defaultinfo
  26.   {
  27.     VESAWORD Mode;
  28.     VESAWORD Width;
  29.     VESAWORD Height;
  30.     VESACHAR CharacterWidth;
  31.     VESACHAR CharacterHeight;
  32.     VESACHAR NumberOfMemoryPlanes;
  33.     VESACHAR NumberOfBitsPerPixel;
  34.     VESACHAR NumberOfBanks;
  35.     VESACHAR MemoryModelType;
  36.     VESACHAR SizeOfBank;
  37.     VESACHAR NumberofPages;
  38.     VESACHAR RedMaskSize;
  39.     VESACHAR RedMaskPosition;
  40.     VESACHAR GreenMaskSize;
  41.     VESACHAR GreenMaskPosition;
  42.     VESACHAR BlueMaskSize;
  43.     VESACHAR BlueMaskPosition;
  44.     VESACHAR ReservedMaskSize;
  45.     VESACHAR ReservedMaskPosition;
  46.   };
  47.  
  48. static struct _defaultinfo default_infos[DEFAULT_MODES]
  49.   = { { 0x100,  640,  400, 8, 16, 1,  8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  50.       { 0x101,  640,  480, 8, 16, 1,  8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  51.       { 0x102,  800,  600, 8, 16, 1,  4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  52.       { 0x103,  800,  600, 8, 16, 1,  8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  53.       { 0x104, 1024,  768, 8, 16, 1,  4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  54.       { 0x105, 1024,  768, 8, 16, 1,  8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  55.       { 0x106, 1280, 1024, 8, 16, 1,  4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  56.       { 0x107, 1280, 1024, 8, 16, 1,  8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
  57.       { 0x10D,  320,  200, 8,  8, 1, 16, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 },
  58.       { 0x10E,  320,  200, 8,  8, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 },
  59.       { 0x10F,  320,  200, 8,  8, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 },
  60.       { 0x110,  640,  480, 8, 16, 1, 16, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 },
  61.       { 0x111,  640,  480, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 },
  62.       { 0x112,  640,  480, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 },
  63.       { 0x113,  800,  600, 8, 16, 1, 16, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 },
  64.       { 0x114,  800,  600, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 },
  65.       { 0x115,  800,  600, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 },
  66.       { 0x116, 1024,  768, 8, 16, 1, 16, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 },
  67.       { 0x117, 1024,  768, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 },
  68.       { 0x118, 1024,  768, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 },
  69.       { 0x119, 1280, 1024, 8, 16, 1, 16, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 },
  70.       { 0x11A, 1280, 1024, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 },
  71.       { 0x11B, 1280, 1024, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 } };
  72.  
  73. static struct __access
  74.   {
  75.     VESAWORD Segment, Offset;
  76.     int      Size, flag;
  77.     VESAPTR  Mem;
  78.     struct __access *next;
  79.   } *access_root = NULL;
  80.  
  81.  
  82. static VESAPTR GetMemAccess(VESAWORD Segment, VESAWORD Offset, int Size, int flag)
  83. {
  84.   struct __access *ptr;
  85.  
  86.   ptr = access_root;
  87.   while ((ptr != NULL) &&
  88.          ((ptr->Segment != Segment) ||
  89.           (ptr->Offset  != Offset)  ||
  90.           (ptr->Size    != Size)    ||
  91.           (ptr->flag    != flag)))
  92.     ptr = ptr->next;
  93.   if (ptr != NULL)
  94.     return(ptr->Mem);
  95.   else
  96.     {
  97.       VESAPTR Mem;
  98.       int     first, last, offs;
  99.  
  100.       offs  = (Segment << 4) + Offset;
  101.       first = (offs / 4096) * 4096;
  102.       last  = ((offs + Size) / 4096) * 4096 + 4096 - 1;
  103.       if ((Mem = _memaccess(first, last, flag)) == NULL)
  104.         return(NULL);
  105.       if ((ptr = malloc(sizeof(struct __access))) != NULL)
  106.         {
  107.           ptr->Segment = Segment;
  108.           ptr->Offset  = Offset;
  109.           ptr->Size    = Size;
  110.           ptr->flag    = flag;
  111.           ptr->Mem     = Mem + offs - first;
  112.           ptr->next    = access_root;
  113.           access_root  = ptr;
  114.         }
  115.       return(Mem + offs - first);
  116.     }
  117. }
  118.  
  119. VESABOOL DosVesaGetInfo(PVESAINFO pVesaInfo)
  120. {
  121.   union REGS r;
  122.   VESAWORD *p, i;
  123. #pragma pack(1)
  124.   union
  125.     {
  126.       struct
  127.         {
  128.           VESACHAR  signature[4];
  129.           VESAWORD  version;
  130.           PVESACHAR oem;
  131.           VESACHAR  capabilities[4];
  132.           PVESAWORD modes;
  133.         } info;
  134.       char fill[256];
  135.     } Info;
  136. #pragma pack(4)
  137.  
  138.   r.x.ax  = 0x4f00;
  139.   r.e.edi = (unsigned long) &Info;
  140.   _int86(0x10, &r, &r);
  141.   if ((r.x.ax != 0x004f) || (memcmp(Info.info.signature, "VESA", 4) != 0))
  142.     return(FALSE);
  143.   pVesaInfo->Version = Info.info.version;
  144.   pVesaInfo->OEMName = Info.info.oem;
  145.   p = Info.info.modes;
  146.   for (i = 0; p[i] != 0xFFFF; i++);
  147.   if ((pVesaInfo->Modes = malloc((i + 4) * sizeof(VESAWORD))) == NULL)
  148.     pVesaInfo->Modes = p;
  149.   else
  150.     {
  151.       memcpy(pVesaInfo->Modes, p, i * sizeof(VESAWORD));
  152.       pVesaInfo->Modes[i + 0] = 0x12;
  153.       pVesaInfo->Modes[i + 1] = 0x13;
  154.       pVesaInfo->Modes[i + 2] = 0x6A;
  155.       pVesaInfo->Modes[i + 3] = 0xFFFF;
  156.     }
  157.   return(TRUE);
  158. }
  159.  
  160. VESABOOL DosVesaGetModeInfo(VESAWORD Mode, PVESAMODEINFO pVesaModeInfo)
  161. {
  162.   union REGS r;
  163.   int  i;
  164. #pragma pack(1)
  165.   union
  166.     {
  167.       struct
  168.         {
  169.           VESAWORD mode_attr;
  170.           VESACHAR window_a_attr;
  171.           VESACHAR window_b_attr;
  172.           VESAWORD window_gran;
  173.           VESAWORD window_size;
  174.           VESAWORD window_a_start;
  175.           VESAWORD window_b_start;
  176.           VESAPTR  window_fun;
  177.           VESAWORD bytes_per_line;
  178.           VESAWORD width;
  179.           VESAWORD height;
  180.           VESACHAR char_width;
  181.           VESACHAR char_height;
  182.           VESACHAR num_planes;
  183.           VESACHAR num_bits;
  184.           VESACHAR num_banks;
  185.           VESACHAR mem_model;
  186.           VESACHAR bank_size;
  187.           VESACHAR num_pages;
  188.           VESACHAR reserved;
  189.           VESACHAR red_mask_size;
  190.           VESACHAR red_mask_pos;
  191.           VESACHAR green_mask_size;
  192.           VESACHAR green_mask_pos;
  193.           VESACHAR blue_mask_size;
  194.           VESACHAR blue_mask_pos;
  195.           VESACHAR res_mask_size;
  196.           VESACHAR res_mask_pos;
  197.           VESACHAR direct_mode_info;
  198.         } info;
  199.       char fill[256];
  200.     } Info;
  201. #pragma pack(4)
  202.  
  203.   if ((Mode == 0x12) || (Mode == 0x13) || (Mode == 0x6A))
  204.     {
  205.       if (Mode == 0x6A)
  206.         *pVesaModeInfo = standard_infos[2];
  207.       else
  208.         *pVesaModeInfo = standard_infos[Mode - 0x12];
  209.       pVesaModeInfo->WindowAStart = GetMemAccess(0xA000, 0, 64 * 1024, 1);
  210.       pVesaModeInfo->WindowBStart = pVesaModeInfo->WindowAStart;
  211.       return(TRUE);
  212.     }
  213.   r.x.ax  = 0x4f01;
  214.   r.x.cx  = Mode;
  215.   r.e.edi = (unsigned long) &Info;
  216.   _int86(0x10, &r, &r);
  217.   if (r.x.ax != 0x004f)
  218.     {
  219.       pVesaModeInfo->ModeAttributes = 0;
  220.       return(FALSE);
  221.     }
  222.   pVesaModeInfo->ModeAttributes       = Info.info.mode_attr;
  223.   pVesaModeInfo->WindowAAttributes    = Info.info.window_a_attr;
  224.   pVesaModeInfo->WindowBAttributes    = Info.info.window_b_attr;
  225.   pVesaModeInfo->WindowGranularity    = Info.info.window_gran;
  226.   pVesaModeInfo->WindowSize           = Info.info.window_size;
  227.   pVesaModeInfo->WindowAStart         = GetMemAccess(Info.info.window_a_start, 0, pVesaModeInfo->WindowSize * 1024, pVesaModeInfo->WindowAAttributes & 4 ? 1 : 0);
  228.   pVesaModeInfo->WindowBStart         = GetMemAccess(Info.info.window_b_start, 0, pVesaModeInfo->WindowSize * 1024, pVesaModeInfo->WindowBAttributes & 4 ? 1 : 0);
  229.   pVesaModeInfo->SetWindowFunc        = DosVesaSetWindow;
  230.   pVesaModeInfo->GetWindowFunc        = DosVesaGetWindow;
  231.   pVesaModeInfo->BytesPerScanline     = Info.info.bytes_per_line;
  232.   if (pVesaModeInfo->ModeAttributes & 2)
  233.     {
  234.       pVesaModeInfo->Width                = Info.info.width;
  235.       pVesaModeInfo->Height               = Info.info.height;
  236.       pVesaModeInfo->CharacterWidth       = Info.info.char_width;
  237.       pVesaModeInfo->CharacterHeight      = Info.info.char_height;
  238.       pVesaModeInfo->NumberOfMemoryPlanes = Info.info.num_planes;
  239.       pVesaModeInfo->NumberOfBitsPerPixel = Info.info.num_bits;
  240.       pVesaModeInfo->NumberOfBanks        = Info.info.num_banks;
  241.       pVesaModeInfo->MemoryModelType      = Info.info.mem_model;
  242.       pVesaModeInfo->SizeOfBank           = Info.info.bank_size;
  243.       pVesaModeInfo->NumberofPages        = Info.info.num_pages;
  244.       pVesaModeInfo->RedMaskSize          = Info.info.red_mask_size;
  245.       pVesaModeInfo->RedMaskPosition      = Info.info.red_mask_pos;
  246.       pVesaModeInfo->GreenMaskSize        = Info.info.green_mask_size;
  247.       pVesaModeInfo->GreenMaskPosition    = Info.info.green_mask_pos;
  248.       pVesaModeInfo->BlueMaskSize         = Info.info.blue_mask_size;
  249.       pVesaModeInfo->BlueMaskPosition     = Info.info.blue_mask_pos;
  250.       pVesaModeInfo->ReservedMaskSize     = Info.info.res_mask_size;
  251.       pVesaModeInfo->ReservedMaskPosition = Info.info.res_mask_pos;
  252.       switch (pVesaModeInfo->NumberOfBitsPerPixel)
  253.         {
  254.           case 15:
  255.             pVesaModeInfo->NumberOfBitsPerPixel = 16;
  256.           case 16:
  257.             if ((pVesaModeInfo->RedMaskSize == 0) ||
  258.                 (pVesaModeInfo->RedMaskSize   +
  259.                  pVesaModeInfo->GreenMaskSize +
  260.                  pVesaModeInfo->BlueMaskSize  +
  261.                  pVesaModeInfo->ReservedMaskPosition != 16))
  262.               memcpy(&pVesaModeInfo->RedMaskSize, &default_infos[11].RedMaskSize,
  263.                      &default_infos[11].ReservedMaskPosition -
  264.                      &default_infos[11].RedMaskSize + sizeof(VESACHAR));
  265.             pVesaModeInfo->MemoryModelType = 6;
  266.             break;
  267.           case 24:
  268.             if ((pVesaModeInfo->RedMaskSize == 0) ||
  269.                 (pVesaModeInfo->RedMaskSize   +
  270.                  pVesaModeInfo->GreenMaskSize +
  271.                  pVesaModeInfo->BlueMaskSize  +
  272.                  pVesaModeInfo->ReservedMaskPosition != 24))
  273.               memcpy(&pVesaModeInfo->RedMaskSize, &default_infos[13].RedMaskSize,
  274.                      &default_infos[13].ReservedMaskPosition -
  275.                      &default_infos[13].RedMaskSize + sizeof(VESACHAR));
  276.             pVesaModeInfo->MemoryModelType = 6;
  277.             break;
  278.           default:
  279.             if (pVesaModeInfo->NumberOfBitsPerPixel <= 8)
  280.               memset(&pVesaModeInfo->RedMaskSize, 0,
  281.                      &default_infos[13].ReservedMaskPosition -
  282.                      &default_infos[13].RedMaskSize + sizeof(VESACHAR));
  283.         }
  284.       return(TRUE);
  285.     }
  286.  
  287.   for (i = 0; i < DEFAULT_MODES; i++)
  288.     if (default_infos[i].Mode == Mode)
  289.       {
  290.         pVesaModeInfo->ModeAttributes |= 2;
  291.         memcpy(&pVesaModeInfo->Width, &default_infos[i].Width,
  292.                sizeof(default_infos[i]) - sizeof(default_infos[i].Mode));
  293.         return(TRUE);
  294.       }
  295.   return(FALSE);
  296. }
  297.  
  298. VESABOOL DosVesaSetMode(VESAWORD Mode)
  299. {
  300.   union REGS r;
  301.  
  302.   r.x.ax = 0x4f02;
  303.   r.x.bx = Mode;
  304.   _int86(0x10, &r, &r);
  305.   return(r.x.ax == 0x004f);
  306. }
  307.  
  308. VESABOOL DosVesaGetMode(PVESAWORD Mode)
  309. {
  310.   union REGS r;
  311.  
  312.   r.x.ax = 0x4f03;
  313.   _int86(0x10, &r, &r);
  314.   *Mode = r.x.bx;
  315.   return(r.x.ax == 0x004f);
  316. }
  317.  
  318. VESABOOL DosVesaSetWindow(VESACHAR Window, VESAWORD Address)
  319. {
  320.   union REGS r;
  321.  
  322.   r.x.ax = 0x4f05;
  323.   r.h.bh = 0x00;
  324.   r.h.bl = Window;
  325.   r.x.dx = Address;
  326.   _int86(0x10, &r, &r);
  327.   return(r.x.ax == 0x004f);
  328. }
  329.  
  330. VESABOOL DosVesaGetWindow(VESACHAR Window, PVESAWORD Address)
  331. {
  332.   union REGS r;
  333.  
  334.   r.x.ax = 0x4f05;
  335.   r.h.bh = 0x01;
  336.   r.h.bl = Window;
  337.   _int86(0x10, &r, &r);
  338.   *Address = r.x.dx;
  339.   return(r.x.ax == 0x004f);
  340. }
  341.  
  342. VESABOOL DosVesaSetScanlineLength(VESAWORD NumberOfPixels)
  343. {
  344.   union REGS r;
  345.  
  346.   r.x.ax = 0x4f06;
  347.   r.h.bl = 0x00;
  348.   r.x.cx = NumberOfPixels;
  349.   _int86(0x10, &r, &r);
  350.   return(r.x.ax == 0x004f);
  351. }
  352.  
  353. VESABOOL DosVesaGetScanlineLength(PVESAWORD BytesPerScanline,
  354.                                   PVESAWORD NumberOfPixels,
  355.                                   PVESAWORD NumberOfScanlines)
  356. {
  357.   union REGS r;
  358.  
  359.   r.x.ax = 0x4f06;
  360.   r.h.bl = 0x01;
  361.   _int86(0x10, &r, &r);
  362.   *BytesPerScanline  = r.x.bx;
  363.   *NumberOfPixels    = r.x.cx;
  364.   *NumberOfScanlines = r.x.dx;
  365.   return(r.x.ax == 0x004f);
  366. }
  367.  
  368. VESABOOL DosVesaSetPalette(VESAWORD   StartIndex,
  369.                            VESAWORD   NumberOfEntries,
  370.                            PCVESACHAR Palette,
  371.                            VESABOOL   Wait)
  372. {
  373.   if ((NumberOfEntries >= 1) && (StartIndex + NumberOfEntries <= 256))
  374.     {
  375.       if (Wait)
  376.         _wait01 (IS1_R, 0x08);
  377.       _outp8 (PEL_IW, StartIndex);
  378.       _outps8dac (PEL_D, Palette, 3 * NumberOfEntries);
  379.       return(TRUE);
  380.     }
  381.   return(FALSE);
  382. }
  383.  
  384. VESABOOL DosVesaGetPalette(VESAWORD  StartIndex,
  385.                            VESAWORD  NumberOfEntries,
  386.                            PVESACHAR Palette)
  387. {
  388.   if ((NumberOfEntries >= 1) && (StartIndex + NumberOfEntries <= 256))
  389.     {
  390.       int i, j;
  391.  
  392.       /* select palette register */
  393.       _outp8(PEL_IR, StartIndex);
  394.  
  395.       for(j = 0; j < NumberOfEntries; j++)
  396.         {
  397.           for(i = 0; i < 10; i++) ;   /* delay (minimum 240ns) */
  398.           *(Palette++) = (int) _inp8(PEL_D);
  399.           for(i = 0; i < 10; i++) ;   /* delay (minimum 240ns) */
  400.           *(Palette++) = (int) _inp8(PEL_D);
  401.           for(i = 0; i < 10; i++) ;   /* delay (minimum 240ns) */
  402.           *(Palette++) = (int) _inp8(PEL_D);
  403.         }
  404.       return(TRUE);
  405.     }
  406.   return(FALSE);
  407. }
  408.  
  409. VESABOOL DosVesaGetCharacter(PVESACHAR pchar)
  410. {
  411.   *pchar = getch();
  412.   return(TRUE);
  413. }
  414.  
  415. VESABOOL DosVesaKeyboardHit(void)
  416. {
  417.   union REGS r;
  418.  
  419.   r.h.ah = 1;
  420.   _int86(0x16, &r, &r);
  421.   return((r.e.eflags & 0x40) == 0);
  422. }
  423.  
  424. VESABOOL DosNoVesaGetInfo(PVESAINFO pVesaInfo)
  425. {
  426.   static VESAWORD Modes[4] = { 0x12, 0x13, 0x6A, 0xFFFF };
  427.  
  428.   pVesaInfo->Version = 0x102;
  429.   pVesaInfo->OEMName = "DOS VESA Replacement by Johannes Martin";
  430.   pVesaInfo->Modes   = Modes;
  431.   return(TRUE);
  432. }
  433.  
  434. VESABOOL DosNoVesaGetModeInfo(VESAWORD Mode, PVESAMODEINFO pVesaModeInfo)
  435. {
  436.   if ((Mode == 0x12) || (Mode == 0x13) || (Mode == 0x6A))
  437.     {
  438.       if (Mode == 0x6A)
  439.         *pVesaModeInfo = standard_infos[2];
  440.       else
  441.         *pVesaModeInfo = standard_infos[Mode - 0x12];
  442.       pVesaModeInfo->WindowAStart = GetMemAccess(0xA000, 0, 64 * 1024, 1);
  443.       pVesaModeInfo->WindowBStart = pVesaModeInfo->WindowAStart;
  444.       return(TRUE);
  445.     }
  446.   return(FALSE);
  447. }
  448.  
  449. VESABOOL DosNoVesaSetMode(VESAWORD Mode)
  450. {
  451.   union REGS r;
  452.  
  453.   if (Mode & 0xFF00)
  454.     return(FALSE);
  455.   r.x.ax = Mode;
  456.   _int86(0x10, &r, &r);
  457.   r.h.ah = 0x0f;
  458.   _int86(0x10, &r, &r);
  459.   return(r.h.al == Mode);
  460. }
  461.  
  462. VESABOOL DosNoVesaGetMode(PVESAWORD Mode)
  463. {
  464.   union REGS r;
  465.  
  466.   r.h.ah = 0x0f;
  467.   _int86(0x10, &r, &r);
  468.   *Mode = r.h.al;
  469.   return(TRUE);
  470. }
  471.  
  472. VESABOOL DosNoVesaSetWindow(VESACHAR Window, VESAWORD Address)
  473. {
  474.   return(TRUE);
  475. }
  476.  
  477. VESABOOL DosNoVesaGetWindow(VESACHAR Window, PVESAWORD Address)
  478. {
  479.   *Address = 0;
  480.   return(TRUE);
  481. }
  482.  
  483. VESABOOL DosNoVesaSetScanlineLength(VESAWORD NumberOfPixels)
  484. {
  485.   return(FALSE);
  486. }
  487.  
  488. VESABOOL DosNoVesaGetScanlineLength(PVESAWORD BytesPerScanline,
  489.                                     PVESAWORD NumberOfPixels,
  490.                                     PVESAWORD NumberOfScanlines)
  491. {
  492.   union REGS r;
  493.  
  494.   r.h.ah = 0x0f;
  495.   _int86(0x10, &r, &r);
  496.   switch (r.h.al)
  497.     {
  498.       case 0x12:
  499.         *BytesPerScanline  = 80;
  500.         *NumberOfPixels    = 640;
  501.         *NumberOfScanlines = 480;
  502.         return(TRUE);
  503.       case 0x13:
  504.         *BytesPerScanline  = 320;
  505.         *NumberOfPixels    = 320;
  506.         *NumberOfScanlines = 200;
  507.         return(TRUE);
  508.       case 0x6A:
  509.         *BytesPerScanline  = 100;
  510.         *NumberOfPixels    = 800;
  511.         *NumberOfScanlines = 600;
  512.         return(TRUE);
  513.     }
  514.   return(FALSE);
  515. }
  516.  
  517. VESABOOL DosMouseOpen(void)
  518. {
  519.   union REGS   r;
  520.   VESAWORD     Mode, Width, Height;
  521.   VESAMODEINFO Info;
  522.   VESABOOL     rc;
  523.   VESACHAR     BiosMode, *BiosAddr;
  524.  
  525.   VesaGetMode(&Mode);
  526.   if (VesaGetModeInfo(Mode, &Info))
  527.     if (Info.ModeAttributes & 0x10)
  528.       {
  529.         textmode = FALSE;
  530.         Width    = Info.Width - 1;
  531.         Height   = Info.Height - 1;
  532.       }
  533.     else
  534.       {
  535.         textmode = TRUE;
  536.         Width    = (Info.Width - 1) * 8;
  537.         Height   = (Info.Height - 1) * 8;
  538.       }
  539.   else
  540.     {
  541.       textmode = TRUE;
  542.       r.h.ah   = 0x0f;
  543.       _int86(0x10, &r, &r);
  544.       Width    = (r.h.ah - 1) * 8;
  545.       Height   = 24 * 8;
  546. /*      r.x.ax   = 0x1130;
  547.       r.h.bh   = 0;
  548.       r.h.dl   = 0;
  549.       _int86(0x10, &r, &r);
  550.       if (r.h.dl == 0)
  551.         Height = 24 * 8;
  552.       else
  553.         Height = r.h.dl * 8;
  554. */    }
  555.   if (!textmode)
  556.     {
  557.       BiosAddr  = GetMemAccess(0x40, 0x49, 1, 1);
  558.       BiosMode  = *BiosAddr;
  559.       *BiosAddr = 0x6;
  560.     }
  561.   r.x.ax = 0x0000;
  562.   _int86(0x33, &r, &r);
  563.   if (!textmode)
  564.     *BiosAddr = BiosMode;
  565.   rc = r.x.ax == 0xffff;
  566.   r.x.ax   = 0x0007;
  567.   r.x.cx   = 0x0000;
  568.   r.x.dx   = Width;
  569.   _int86(0x33, &r, &r);
  570.   r.x.ax   = 0x0008;
  571.   r.x.cx   = 0x0000;
  572.   r.x.dx   = Height;
  573.   _int86(0x33, &r, &r);
  574.   return(rc);
  575. }
  576.  
  577. VESABOOL DosMouseClose(void)
  578. {
  579.   union REGS r;
  580.  
  581.   r.x.ax = 0x0000;
  582.   _int86(0x33, &r, &r);
  583.   return(TRUE);
  584. }
  585.  
  586. VESABOOL DosMouseShow(void)
  587. {
  588.   union REGS r;
  589.  
  590.   r.x.ax = 0x0001;
  591.   _int86(0x33, &r, &r);
  592.   return(TRUE);
  593. }
  594.  
  595. VESABOOL DosMouseHide(void)
  596. {
  597.   union REGS r;
  598.  
  599.   r.x.ax = 0x0002;
  600.   _int86(0x33, &r, &r);
  601.   return(TRUE);
  602. }
  603.  
  604. VESABOOL DosMouseSetPosition(VESAWORD x, VESAWORD y)
  605. {
  606.   union REGS r;
  607.  
  608.   if (textmode)
  609.     {
  610.       r.x.cx *= 8;
  611.       r.x.dx *= 8;
  612.     }
  613.   r.x.ax = 0x0004;
  614.   r.x.cx = x;
  615.   r.x.dx = y;
  616.   _int86(0x33, &r, &r);
  617.   return(TRUE);
  618. }
  619.  
  620. VESABOOL DosMouseGetPosition(PVESAWORD x, PVESAWORD y)
  621. {
  622.   union REGS r;
  623.  
  624.   r.x.ax = 0x0003;
  625.   _int86(0x33, &r, &r);
  626.   *x = r.x.cx;
  627.   *y = r.x.dx;
  628.   if (textmode)
  629.     {
  630.       *x /= 8;
  631.       *y /= 8;
  632.     }
  633.   return(TRUE);
  634. }
  635.  
  636. VESABOOL DosMouseGetEvent(PVESAWORD x, PVESAWORD y, PVESAWORD status, VESABOOL wait)
  637. {
  638.   static VESAWORD oldx      = 0;
  639.   static VESAWORD oldy      = 0;
  640.   static VESAWORD oldstatus = 0;
  641.   union REGS r;
  642.   VESABOOL event;
  643.  
  644.   do
  645.     {
  646.       r.x.ax = 0x0003;
  647.       _int86(0x33, &r, &r);
  648.       event = (r.x.cx != oldx) || (r.x.dx != oldy) || (r.x.bx != oldstatus);
  649.     }
  650.   while (wait && !event);
  651.   *x      = oldx      = r.x.cx;
  652.   *y      = oldy      = r.x.dx;
  653.   *status = oldstatus = r.x.bx;
  654.   if (textmode)
  655.     {
  656.       *x /= 8;
  657.       *y /= 8;
  658.     }
  659.   return(event);
  660. }
  661.